//
//  ZCTabBarController.m
//  ZCBaiSi
//
//  Created by zc on 16/7/4.
//  Copyright © 2016年 zc. All rights reserved.
//

#import "ZCTabBarController.h"
#import "ZCTabBar.h"
#import "ZCEssenceViewController.h"
#import "ZCNewViewController.h"
#import "ZCFollowViewController.h"
#import "ZCMeViewController.h"
#import "ZCNavigationController.h"
@interface ZCTabBarController ()

@end

@implementation ZCTabBarController

#pragma mark --初始化
- (void)viewDidLoad {
    [super viewDidLoad];
    //设置所有的UITabBarItem的文字属性
    [self setupItemTitleTextAttributes];
    
    //添加子控制器
    [self setupChildViewControllers];
    
    //更换TabBar KVC
    [self setupTabBar];
}

- (void)setupItemTitleTextAttributes{
    UITabBarItem *item = [UITabBarItem appearance];
    //普通状态下文字属性
    NSMutableDictionary *normalAtts = [NSMutableDictionary dictionary];
    normalAtts[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    normalAtts[NSForegroundColorAttributeName] = [UIColor grayColor];
    [item setTitleTextAttributes:normalAtts forState:UIControlStateNormal];
    //选中状态下文字属性
    NSMutableDictionary *selectedAtts = [NSMutableDictionary dictionary];
    selectedAtts[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    [item setTitleTextAttributes:selectedAtts forState:UIControlStateSelected];
}

- (void)setupChildViewControllers{
    
     [self setUpOneChildViewController:[[ZCNavigationController alloc] initWithRootViewController:[[ZCEssenceViewController alloc]init]] title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    [self setUpOneChildViewController:[[ZCNavigationController alloc] initWithRootViewController:[[ZCFollowViewController alloc]init]] title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    [self setUpOneChildViewController:[[ZCNavigationController alloc] initWithRootViewController:[[ZCNewViewController alloc]init]] title:@"新帖" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    [self setUpOneChildViewController:[[ZCNavigationController alloc] initWithRootViewController:[[ZCMeViewController alloc]init]] title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
   
}

- (void)setupTabBar{
    [self setValue:[[ZCTabBar alloc]init] forKey:@"tabBar"];
}

//初始化一个子控制器
- (void)setUpOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    vc.tabBarItem.title = title;
    if (image.length) {
        vc.tabBarItem.image = [UIImage imageNamed:image];
    }
    if (selectedImage.length) {
        vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];

    }
      [self addChildViewController:vc];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
